package searchteam.client.ui.widgets;

import searchteam.client.beansMirrors.PersonMirror;
import searchteam.client.services.SearchTeamServicesAsync;
import searchteam.client.ui.callbacks.createPersonCallback;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;

public class CreatePersonPopUp extends DialogBox {
	
	PersonMirror person;
	SearchTeamServicesAsync services;
	DataPanel panel;
	
	public CreatePersonPopUp(DataPanel p, SearchTeamServicesAsync s) {
		
		person = null;
		services = s;
		panel = p;
		
		Grid mainPanel = new Grid(5, 2);
		
		this.setTitle("Creation de Personne");
		this.setText("Creation de Personne");
		this.setPopupPosition(100, 100);
		
		final TextBox nameTB = new TextBox();
		final TextBox firstNameTB = new TextBox();
		final TextBox telTB = new TextBox();
		final TextBox mailTB = new TextBox();
		
		Button buttonOK = new Button("enregistrer");
		Button buttonKO = new Button("annuler");
		
		buttonOK.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				person = new PersonMirror(nameTB.getText(), firstNameTB.getText(), telTB.getText(), mailTB.getText());
				services.createPerson(person, new createPersonCallback(panel));
				CreatePersonPopUp.this.hide();
			}
		});
		
		buttonKO.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				CreatePersonPopUp.this.hide();
			}
		});
		
		mainPanel.setWidget(0, 0, new Label("Nom"));
		mainPanel.setWidget(0, 1, nameTB);
		mainPanel.setWidget(1, 0, new Label("Prenom"));
		mainPanel.setWidget(1, 1, firstNameTB);
		mainPanel.setWidget(2, 0, new Label("Tel"));
		mainPanel.setWidget(2, 1, telTB);
		mainPanel.setWidget(3, 0, new Label("Mail"));
		mainPanel.setWidget(3, 1, mailTB);
		mainPanel.setWidget(4, 0, buttonOK);
		mainPanel.setWidget(4, 1, buttonKO);
		
		this.add(mainPanel);
		this.show();
	}

}
